using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL {

/// <summary>
/// The BloodGroupCodeTableManager class is responsible for managing BO.BloodGroupCodeTable objects in the system.
/// </summary>
[DataObjectAttribute()]
public class BloodGroupCodeTableManager
  {

#region "Public Methods"

/// <summary>
/// Gets a list with all BloodGroupCodeTable objects in the database.
/// </summary>
/// <returns>A list with all BloodGroupCodeTable from the database when the database contains any, or null otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Select, true)]
public static BloodGroupCodeTableList GetList(){
return BloodGroupCodeTableDB.GetList();
}

/// <summary>
/// Gets a single BloodGroupCodeTable from the database without its data.
/// </summary>
/// <param name="BloodGroupCode">The BloodGroupCode of the BloodGroupCodeTable in the database.</param>
/// <returns>A BloodGroupCodeTable object when the BloodGroupCode exists in the database, or <see langword="null"/> otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static BloodGroupCodeTable GetItem(short BloodGroupCode,int SchoolKey){
return GetItem(BloodGroupCode,SchoolKey, false);
}

/// <summary>
/// Gets a single BloodGroupCodeTable from the database.
/// </summary>
/// <param name="BloodGroupCode">The BloodGroupCode of the BloodGroupCodeTable in the database.</param>
/// <param name="getBloodGroupCodeTableRecords">Determines whether to load all associated BloodGroupCodeTable records as well.</param>
/// <returns>
/// A BloodGroupCodeTable object when the BloodGroupCode exists in the database, or <see langword="null"/> otherwise.
/// </returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static BloodGroupCodeTable GetItem(short BloodGroupCode,int SchoolKey, bool getBloodGroupCodeTableRecords){
BloodGroupCodeTable myBloodGroupCodeTable = BloodGroupCodeTableDB.GetItem(BloodGroupCode);
if (myBloodGroupCodeTable != null && getBloodGroupCodeTableRecords){
myBloodGroupCodeTable.familyMemberProfileTables = FamilyMemberProfileTableDB.GetListByBloodGroupCode(BloodGroupCode);
}
if (myBloodGroupCodeTable != null && getBloodGroupCodeTableRecords){
myBloodGroupCodeTable.guardianProfileTables = GuardianProfileTableDB.GetListByBloodGroupCode(BloodGroupCode);
}
if (myBloodGroupCodeTable != null && getBloodGroupCodeTableRecords){
myBloodGroupCodeTable.studentProfileTables = StudentProfileTableDB.GetListByBloodGroupCode(BloodGroupCode);
}
if (myBloodGroupCodeTable != null && getBloodGroupCodeTableRecords){
myBloodGroupCodeTable.teacherProfileTables = TeacherProfileTableDB.GetListByBloodGroupCode(BloodGroupCode,SchoolKey);
}
if (myBloodGroupCodeTable != null && getBloodGroupCodeTableRecords){
myBloodGroupCodeTable.userProfileTables = UserProfileTableDB.GetListByBloodGroupCode(BloodGroupCode);
}
return myBloodGroupCodeTable;
}

/// <summary>
/// Saves a BloodGroupCodeTable in the database.
/// </summary>
/// <param name="myBloodGroupCodeTable">The BloodGroupCodeTable instance to save.</param>
/// <returns>The new BloodGroupCode if the BloodGroupCodeTable is new in the database or the existing BloodGroupCode when an item was updated.</returns>
[DataObjectMethod(DataObjectMethodType.Update, true)]
public static short Save(BloodGroupCodeTable myBloodGroupCodeTable){
using (TransactionScope myTransactionScope = new TransactionScope()){
short bloodGroupCodeTableBloodGroupCode = BloodGroupCodeTableDB.Save(myBloodGroupCodeTable);

//foreach (FamilyMemberProfileTable myFamilyMemberProfileTable in myBloodGroupCodeTable.familyMemberProfileTables){
//myFamilyMemberProfileTable.BloodGroupCode = bloodGroupCodeTableBloodGroupCode;
//FamilyMemberProfileTableDB.Save(myFamilyMemberProfileTable);
//}
//foreach (GuardianProfileTable myGuardianProfileTable in myBloodGroupCodeTable.guardianProfileTables){
//myGuardianProfileTable.BloodGroupCode = bloodGroupCodeTableBloodGroupCode;
//GuardianProfileTableDB.Save(myGuardianProfileTable);
//}
//foreach (StudentProfileTable myStudentProfileTable in myBloodGroupCodeTable.studentProfileTables){
//myStudentProfileTable.BloodGroupCode = bloodGroupCodeTableBloodGroupCode;
//StudentProfileTableDB.Save(myStudentProfileTable);
//}
//foreach (TeacherProfileTable myTeacherProfileTable in myBloodGroupCodeTable.teacherProfileTables){
//myTeacherProfileTable.BloodGroupCode = bloodGroupCodeTableBloodGroupCode;
//TeacherProfileTableDB.Save(myTeacherProfileTable);
//}
//foreach (UserProfileTable myUserProfileTable in myBloodGroupCodeTable.userProfileTables){
//myUserProfileTable.BloodGroupCode = bloodGroupCodeTableBloodGroupCode;
//UserProfileTableDB.Save(myUserProfileTable);
//}

//  Assign the BloodGroupCodeTable its new (or existing BloodGroupCode).
myBloodGroupCodeTable.BloodGroupCode = bloodGroupCodeTableBloodGroupCode;

myTransactionScope.Complete();

return bloodGroupCodeTableBloodGroupCode;
}
}

/// <summary>
/// Deletes a BloodGroupCodeTable from the database.
/// </summary>
/// <param name="myBloodGroupCodeTable">The BloodGroupCodeTable instance to delete.</param>
/// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Delete, true)]
public static bool Delete(BloodGroupCodeTable myBloodGroupCodeTable){
return BloodGroupCodeTableDB.Delete(myBloodGroupCodeTable.BloodGroupCode);
}

#endregion

}

}
